import { Dict } from 'styled-components/dist/types';

import { PaginationProps } from '@/common';

export interface QA {
  a: string;
  q: string;
  question_id?: string;
  status?: number;
}

export interface HistoryQA {
  content: string;
  obj: string;
  time: string;
}

export interface Index {
  defaultIndex: string;
  text: string;
}

export interface InsertQAReq extends QA {
  collectionId: string;
  indexed: Index[];
}

export type Todo = {
  title: string;
  subTitle: string;
  route: string;
  key: string;
  actionTitle: string;
  actionTip: string;
  tip?: React.ReactNode;
};

export type KnowMenu = {
  key: number;
  title: string;
  firstTitle: string;
  secondTitle: string;
  children?: React.ReactNode;
};

export type SubQuestionType = {
  questionId: string;
  text: string;
  answer: string;
  chatId: string;
  status: number;
  annoA?: string;
  annoId?: string;
  annoQ?: string;
  role?: string;
  roleName?: string;
  time?: string;
  qaList?: HistoryQA[];
};

export type BaseQuestionType = {
  _id: string;
  keyQuestionId: string;
  keyQuestionText: string;
  keyQuestionChatId: string;
  keyQuestionAnswer: string;
  updateTime?: string;
  createTime?: string;
  questionList?: SubQuestionType[];
  status: number;
  annoA?: string;
  annoId?: string;
  annoQ?: string;
  role?: string;
  roleName?: string;
  proTotal?: number;
  total?: number;
  qaList?: HistoryQA[];
  qaId?: string;
  feedback?: string;
  keyAnswerId?: string;
  category?: string;
};

export type ConnectorChildTask = {
  task_doc_type: string;
  task_fail_reason: string;
  task_status: 'FAIL' | 'WARNING';
  task_url: string;
  task_status_cn: string;
};

export type connectorTypeReq = {
  _id: string;
  name: string;
  type: string;
  urls: {};
  dbConfig: Dict;
  datasetName: string;
  status: number;
  progress: number;
  latestSyncTime: string;
  remainingTime: string;
  status_cn?: string;
  child_task_status?: ConnectorChildTask[];
};

export type validateReq = {
  type: string;
  urls: {};
  dbConfig: Dict;
};

export interface UnknowQuestionType extends BaseQuestionType {
  questionList: SubQuestionType[];
}

export interface FeedbackQuestionType extends BaseQuestionType {
  feedback: string;
}

export interface FreqQuestionType extends UnknowQuestionType {
  frequence: number;
}

export type FaqCollection = {
  collectionId: string;
  collectionName: string;
  createTime: string;
  updateTime: string;
};

export type FaqDataset = {
  datasetId: string;
  datasetName: string;
  createTime: string;
  updateTime: string;
  children: FaqCollection[];
};

export type SpecialtyType = {
  _id: string;
  text: string;
  createTime: string;
  updateTime: string;
};

export type WordType = {
  _id?: string;
  subject: string;
  members: string[];
  createTime?: string;
  updateTime?: string;
};

export type NewSpecialtyType = {
  id: string;
  text: string;
};

export type GovStatisType = {
  questionsTotal: number;
  collectionsTotal: number;
  termsTotal: number;
  auditTotal: number;
};

export enum Category {
  ExpireCollection = '老化知识',
  DuplicateCollection = '重复知识',
  ConflictCollection = '冲突知识',

  FrequentQuestion = '高频问',
  UnknownQuestion = '未知问',
  FeedbackQuestion = '点踩问',
  FeedbackGoodQuestion = '点赞问',

  SpecialtyWord = '专业词',
  SynonymWord = '近义词',
  SensitiveWord = '敏感词',
}

/**
 * 数据集
 */
export type KnowCollection = {
  _id: string;
  parentId: string;
  tmbId: string;
  type: string;
  name: string;
  forbid: boolean;
  datasetName: string;
  trainingType: string;
  fileId: string;
  rawLink: string;
  createTime: string;
  updateTime: string;
  expiredTime: string;
  category?: Category;
  collectionId: string;
  isDeleted?: boolean;
  fileName?: string;
};

/**
 * 重复数据集
 */
export type DuplicateCollection = {
  fileName?: string;
  name: string;
  datasetId: string;
  datasetName: string;
  collectionId: string;
  previewUrl: string;
  forbid: boolean;
  updateTime: string;
  createTime: string;
  status: number;
  similarity: number;
  fileUrl: string;
  isDeleted?: boolean;
};

export type KnowSimilarityCollection = KnowCollection & {
  previewUrl: string;
  fileUrl: string;
  status: number;
  duplicateList: DuplicateCollection[];
};

export type TodoGov = (
  | KnowCollection
  | KnowSimilarityCollection
  | WordType
  | SpecialtyType
  | UnknowQuestionType
  | FeedbackQuestionType
  | FreqQuestionType
) & {
  category: Category;
  status: number;
};

export type ProcessSimilarityReq = {
  collection_id: string;
  is_keep: boolean;
  app_id: string;
};

export type MarkQuestionReq = {
  id: string;
  collection_id?: string;
  datas: QA[];
  is_ignore?: boolean;
  type: string; // unknown, feedback, frequent
  appId?: string;
};

export type MarkQuestionResItem = {
  question_id: string;
  annoId: string;
};

export enum QuestionType {
  Unknown = 'unknown',
  Feedback = 'feedback',
  Frequent = 'frequent',
  similarity = 'similarity',
}

export type AnnotationType = QA & {
  _id: string;
  recordId: string;
  createTime: string;
  updateTime: string;
  type: QuestionType;
  datasetName: string;
  chatId: string;
  appId: string;
  shareId: string;
};

export type AnnotationOpType = {
  ids: string[];
};

export type FilePreInfoType = {
  previewUrl: string;
  fileUrl: string;
  forbid: boolean;
};

export type UpdateExpireReq = UpdateExpireListReq & {
  collectionIdList?: UpdateExpireListReq[];
};
export type UpdateExpireListReq = {
  collection_id?: string;
  expired_time?: string;
};

export interface KnowUnknownReq extends PaginationProps {
  appId: string;
  startTime: string;
  endTime: string;
}
export type LineChartDataItem = {
  _id: string;
  unknownCount?: number;
  feedbackCount?: number;
  total_solved?: number;
  total_unsolved?: number;
};

export interface ClusterItemsType {
  qaId_list: string[];
  query: string;
  id?: string;
}
export interface UnknownItemType {
  keyQuestionQaId: string;
  keyQuestionText: string;
  clusterItems: ClusterItemsType[];
  appId: string;
  clusterSize: number;
  id: string;
  mentionedTimes: number;
  time: string;
}

export interface AnnotationTypeItem {
  appId: string;
  keyQuestionQaId: string;
  question: string;
  answer: string;
  datasetId: string;
  qaIdList: string[];
  experiodTime: string;
}

export interface DislikeQuestionAnnotationType {
  id: string;
  appId: string;
  qaId: string;
  question: string;
  answer: string;
  datasetId: string;
  experiodTime: string;
}

export interface OptimizedistType {
  fileId: string;
  collectionId: string;
  datasetId: string;
  datasetName: string;
  fileName: string;
  reviewStatus: string;
  message: string;
  optimize_text: string[];
  size: string;
  passTime: string;
  appId: string;
  creatUserName: string;
  createTime: string;
}

export interface AutoCorrectListType {
  correctedText: string;
  originalText: string;
  count: number;
  word: string;
  chunkIdList: string[];
  originalIndices: number;
}
export interface AutoCorrectTrunksType {
  _id: string;
  text: string;
  chunkIndex: number;
}
export interface IgnoreAutoCorrectType {
  collectionId?: string;
  appId?: string;
  type: string;
  word?: string[];
  optimizeText?: string[];
  status: number;
  ignoreList?: IgnoreListReq[];
  originalIndices?: number[];
}
export interface IgnoreListReq {
  collectionId?: string;
  appId?: string;
  ids?: string[];
}
export interface RepetitionType {
  _id: string;
  datasetId: string;
  name: string;
  hashRawText: string;
  createTime: string;
  collectionId: string;
  datasetName: string;
  username: string;
  datasetPath: string;
}
